package com.wzdigit.wms.wms.controller.TransferWareHouse;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.request.transfer.SearchInvRequest;
import com.wzdigit.wms.basic.client.response.transfer.InvLocGoodsListResponse;
import com.wzdigit.wms.basic.client.response.transfer.InvLocListResponse;
import com.wzdigit.wms.basic.client.response.transfer.InvZoneListResponse;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.transfer.InvZoneService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 库位库存-- 前端控制器
 * </p>
 *
 * @author
 * @since 2021-01-12
 */
@RestController
@Api(tags = "库位库存")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class InvZoneController {

    public static final String REQUEST_MODEL = "/invzone";

    @Autowired
    private InvZoneService invZoneService;
    
	/**
	 * 查询库区库存
	 * @param <T>
	 * @param dto
	 * @param pager
	 * @param servletRequest
	 * @param servletResponse
	 * @return
	 */
	@ApiOperation(value = "查询库区库存",notes = "查询库区库存")
	@ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
	@GetMapping(value = REQUEST_MODEL + "/searchInvZone")
	public <T> PagerInfo<List<InvZoneListResponse>> searchInvZone(SearchInvRequest dto,
																  @ApiParam(value = "采购订单号模糊查询", required = false)
																  @RequestParam(required = false) String poNo,
																  @ApiParam(value = "销售订单号模糊查询", required = false)
																  @RequestParam(required = false) String soNo,
																  @ApiParam(value = "销售订单行号模糊查询", required = false)
																  @RequestParam(required = false) String soItem,
																  @ApiParam(value = "货品编码模糊查询", required = false)
																  @RequestParam(required = false) String filter,
																  Pager<T> pager,
																  HttpServletRequest servletRequest,
																  HttpServletResponse servletResponse) {
		try {
			return invZoneService.searchInvZone(dto, poNo, soNo, soItem, filter, pager);
		} catch (RestStatusException e) {
			e.printStackTrace();
			servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
			throw e;
		}
	}
	
	/**
	 * 查询库位库存
	 * @param
	 * @param pager
	 * @param servletRequest
	 * @param servletResponse
	 * @return
	 */
	@ApiOperation(value = "查询库位库存",notes = "查询库位库存")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/searchInvLoc")
    public <T> PagerInfo<List<InvLocListResponse>> searchInvLoc(
    		SearchInvRequest dto, Pager<T> pager, 
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return invZoneService.searchInvLoc(dto, pager);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

	@ApiOperation(value = "根据库位库存查找sn",notes = "根据库位库存查找sn")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/searchGoodsByInvLoc")
    public PagerInfo<List<InvLocGoodsListResponse>> searchGoodsByInvLoc(
    		SearchInvRequest dto,Pager<?> pager,
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return invZoneService.searchGoodsByInvLoc(dto,pager);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
	
	/**
	 * @param dto
	 * @param servletRequest
	 * @param servletResponse
	 * @throws Exception 
	 */
	@ApiOperation(value = "导出库区库存",notes = "导出库区库存")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/export")
    public void export(SearchInvRequest dto, 
    		@ApiParam(value = "采购订单号模糊查询", required = false) 
    		@RequestParam(required = false) String poNo,
    		@ApiParam(value = "销售订单号模糊查询", required = false) 
    		@RequestParam(required = false) String soNo,
    		@ApiParam(value = "销售订单行号模糊查询", required = false) 
    		@RequestParam(required = false) String soItem,
    		@ApiParam(value = "货品编码模糊查询", required = false) 
    		@RequestParam(required = false) String filter,
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) throws Exception {
        try {
            invZoneService.export(dto, poNo, soNo, soItem, filter, servletRequest, servletResponse);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

	@ApiOperation(value = "库存报表主档【新】",notes = "库存报表主档【新】")
	@ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
	@GetMapping(value = REQUEST_MODEL + "/searchInvLocNew")
	public <T> PagerInfo<List<InvZoneListResponse>> searchInvLocNew(SearchInvRequest dto,
																  @ApiParam(value = "采购订单号模糊查询", required = false)
																  @RequestParam(required = false) String poNo,
																  @ApiParam(value = "销售订单号模糊查询", required = false)
																  @RequestParam(required = false) String soNo,
																  @ApiParam(value = "销售订单行号模糊查询", required = false)
																  @RequestParam(required = false) String soItem,
																  @ApiParam(value = "货品编码模糊查询", required = false)
																  @RequestParam(required = false) String filter,
															      @ApiParam(value = "仓库类型：1:原材料，2:半成品仓，3:成品", required = false)
																  @RequestParam(required = false) String whsType,
																  Pager<T> pager,
																  HttpServletRequest servletRequest,
																  HttpServletResponse servletResponse) {
		try {
			return invZoneService.searchInvLocNew(dto, poNo, soNo, soItem, whsType, filter, pager);
		} catch (RestStatusException e) {
			e.printStackTrace();
			servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
			throw e;
		}
	}


	@ApiOperation(value = "导出库存主档【新】",notes = "导出库存主档【新】")
	@ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
	@GetMapping(value = REQUEST_MODEL + "/exportNew")
	public void exportNew(SearchInvRequest dto,
						  @ApiParam(value = "采购订单号模糊查询", required = false)
						  @RequestParam(required = false) String poNo,
						  @ApiParam(value = "销售订单号模糊查询", required = false)
						  @RequestParam(required = false) String soNo,
						  @ApiParam(value = "销售订单行号模糊查询", required = false)
						  @RequestParam(required = false) String soItem,
						  @ApiParam(value = "货品编码模糊查询", required = false)
						  @RequestParam(required = false) String filter,
						  @ApiParam(value = "仓库类型：1:原材料，2:半成品仓，3:成品", required = false)
						  @RequestParam(required = false) String whsType,
						  HttpServletRequest servletRequest,
						  HttpServletResponse servletResponse) throws Exception {
		try {
			invZoneService.exportNew(dto, poNo, soNo, soItem, whsType, filter, servletRequest, servletResponse);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}

	@ApiOperation(value = "导出货品清单【新】",notes = "导出货品清单【新】")
	@ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
	@GetMapping(value = REQUEST_MODEL + "/exportGoodsNew")
	public void exportGoodsNew(SearchInvRequest dto,
						  HttpServletRequest servletRequest,
						  HttpServletResponse servletResponse) throws Exception {
		try {
			invZoneService.exportGoodsNew(dto, servletRequest, servletResponse);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}



}
